|
|
|
|
|
|
|
You learned about the major types of errors that you are likely to encounter in your program: |
|
|
|
|
|
|
|
|
· General file errors: These include errors such as File not found and Invalid path. Errors of this type can usually be fixed by the user and then the operation retried. Use Resume as an exit for these types of errors. |
|
|
|
|
|
|
|
|
· Database errors: These include errors related to data entry mistakes, integrity violations, and multiuser-related errors, such as locked records. Errors of this type are best handled by allowing the user to correct the data and attempt the operation again. If you use the Visual Basic data control, you do not have to write error handlersthe data control handles them for you. For operations that do not use the data control, you need to write your own error-handling routines. |
|
|
|
|
|
|
|
|
· Physical media errors: These errors relate to device problems, such as unresponsive printers, downed communications ports, and so on. Sometimes users can fix the problems and continue (such as refilling the paper tray of the printer). Other times, users cannot fix the problem without first exiting the program. It is a good idea to give users the option of exiting the program safely when errors of these types are reported. |
|
|
|
|
|
|
|
|
· Program code errors: These errors occur because of problems within the Visual Basic code itself. Examples of program code errors include Object variable not set and For loop not initialized. Usually the user cannot do anything to fix errors of this type. It is best to encourage the user to report the error to the system administrator and exit the program safely. |
|
|
|
|
|
|
|
|
You also learned that you can declare a global error handler or a local error handler. The advantage of the global error handler is that it allows you to create a single module that handles all expected errors. The disadvantage is that, due to the way Visual Basic keeps track of running routines, you are not able to resume processing at the point the error occurs once you arrive at the global error handler. The advantage of the local error handler is that you are always able to use Resume, Resume Next, or Resume label to continue processing at the point the error occurs. The disadvantage of the local error handler is that you need to add error-handling code to every routine in your program. |
|
|
|
|
|
|
|
|
Finally, you learned how to create an error handler object library that combines local error trapping with global error messages and responses. The error handler object library also contains modules to keep track of the procedures currently running at the time of the error, a process for printing procedure stack dumps to the screen and to a file, and a process that creates an error log on file for later review. |
|
|
|
|
|